package config

import (
	"os"

	"gopkg.in/yaml.v3"
)

// Config represents the configuration structure for MongoDB
type Config struct {
	Mongo struct {
		Host     string `yaml:"host"`
		Port     string `yaml:"port"`
		Username string `yaml:"username"`
		Password string `yaml:"password"`
		Database string `yaml:"database"`
	} `yaml:"mongo"`
}

// LoadConfig loads the configuration from the given file path
func LoadConfig(filePath string) (*Config, error) {
	// Open the YAML file
	file, err := os.Open(filePath)
	if err != nil {
		return nil, err
	}
	defer file.Close()

	// Initialize the configuration structure
	var cfg Config

	// Decode the YAML data into the configuration structure
	decoder := yaml.NewDecoder(file)
	if err := decoder.Decode(&cfg); err != nil {
		return nil, err
	}

	return &cfg, nil
}
